 "use client"
import React, { useEffect } from 'react';
import type { FormProps } from 'antd';
import { Button, Checkbox, Form, Input } from 'antd';
import * as api from '../../../../../utils/https'
type FieldType = {
    name?: string;
    Customer?: string;
    stage?: string;
    bjnum?: string;
    price?: string;
};

export default function Myform(props) {
  console.log(props);
  
    const [form] = Form.useForm();
    useEffect(()=>{
        if(props.title=="编辑"){
            form.setFieldsValue(props.data) 
        }
    },[])
const onFinish: FormProps<FieldType>['onFinish'] = (values) => {
    if(props.title=="添加"){
        let obj={
            ...values
        }
        api.http_addtable(obj)
    }else{
        let obj={
            ...props.data,
            ...values
        }
       api.http_edittable(obj)
    }
    location.reload()
    props.onOk()
  };
 
  return (
    <div>
        <Form
    name="basic"
    onFinish={onFinish}
    form={form}
  >
    <Form.Item<FieldType>
      label="订单标题"
      name="name"
      rules={[{ required: true, message: '订单标题不能为空!' }]}
    >
      <Input />
    </Form.Item>

    <Form.Item<FieldType>
      label="关联客户"
      name="Customer"
      rules={[{ required: true, message: '关联客户不能为空!' }]}
    >
     <Input />
    </Form.Item>
    <Form.Item<FieldType>
      label="订单阶段"
      name="stage"
      rules={[{ required: true, message: '订单阶段不能为空!' }]}
    >
     <Input />
    </Form.Item>
    <Form.Item<FieldType>
      label="报价记录"
      name="bjnum"
      rules={[{ required: true, message: '报价记录不能为空!' }]}
    >
     <Input />
    </Form.Item>
    <Form.Item<FieldType>
      label="报价总金额"
      name="price"
      rules={[{ required: true, message: '报价总金额不能为空!' }]}
    >
     <Input />
    </Form.Item>
    <Form.Item label={null}>
      <Button type="primary" htmlType="submit">
        确定
      </Button>
    </Form.Item>
  </Form>
    </div>
  )
}
